from .Constant import *


class Catalog:
    def __init__(self, data: str):
        self.log_list = []
        self.first_data = data[:14 * 16 * BYTES]

        self.log_list = deal_catalog(data[14 * 16 * BYTES:])


def deal_catalog(data: str):
    log_list = []
    file_num = 0
    loop_count = 0
    next_loop = data[64 * loop_count: 64 * loop_count + 2]
    one_log = ""

    while next_loop != "00" and next_loop != "":
        if (next_loop == "85" or next_loop == "05") and loop_count != 0:
            log_list.append(one_log)
            one_log = ""
            file_num += 1
        one_log += data[64 * loop_count: 64 * (loop_count + 1)]
        loop_count += 1
        next_loop = data[64 * loop_count: 64 * loop_count + 2]
    log_list.append(one_log)
    return log_list
